$(function () {


    $('body').on("click",".unBorder",function(){
        if($(".nows").length>0){
            $(".nows").remove();
            $("input").remove(".logo_choose");
            $("br").remove(".logo");
        }else{
            $('header').after(" <nav class=\"bar bar-tab nows\">\n" +
                "            <a  class=\"tab-item external nows_close\"><span class=\"tab-label\">取消</span></a>\n" +
                "        <a  class=\"tab-item external active\"><span class=\"tab-label logo_del\">删除</span></a>\n" +
                "        </nav>");
            $('.logo').prepend("<input class=\"logo_choose\" type=\"checkbox\">\n"+"<br>");
        }
    }).on("click",".nows_close",function(){
        $(".nows").remove();
        $("input").remove(".logo_choose");
        $("br").remove(".logo");
    }).on("click",".logo_del",function(){
        var functionIds = $(".logo_choose:checked");
        if(functionIds.length<=0){
            Zepto.toast("请选择要删除的消息");
            return;
        }
        functionIds = functionIds.map(function(){
            $(this).parents(".item-content").parents("li").remove();
            return $(this).parents(".item-content").data("id");
        }).get().join(",");
        deleteMsg(functionIds);
    }).on("click",".msgs",function () {
        if($(this).find("div").find(".wm-badge-inline").length>0){
            updateReceiveIdStatus($(this));
        }
    });
    getMessageList(1);

    function deleteMsg (id){


        Zepto.ajax({
            url:baseloaction +'/mobile/uc/op/affiche/deleteReceive',
            type:'post',
            dataType:'json',
            data:{
                'id':id
            },
            success:function (result) {
                if(result.success){
                    Zepto.toast("删除成功");
                }

            },
            error:function (error) {
                Zepto.toast("删除失败");
            }
        });

    }

    function updateReceiveIdStatus (that){
        Zepto.ajax({
            url:baseloaction +'/mobile/uc/op/affiche/updateReceiveIdStatus',
            type:'post',
            dataType:'json',
            data:{
                'id':that.data("id")
            },
            success:function (result) {
                if(result.success){
                        that.find(".wm-badge-inline").remove();
                }
            }
        });
    }
    function getMessageList(pageNo) {
        var params = '';
        var obj={
            url: baseloaction + '/mobile/uc/op/affiche/ajaxQueryUserAfficheList',//请求url
            contextId:'message-list-box',//请求成功后数据内容添加的地方
            pageNo:pageNo,//页面码，可以不传
            pageCall:getMessageList,//分页方法（一般调用自身）
            params:params,//查询参数
            callback:function (pageNo) {}
        };
        loadMobilePathData(obj);
    }



});